<?php 
declare (strict_types = 1);
namespace app\api\controller;
use app\common\controller\Api;
use think\Request;
class Fkmsg extends Api
{
    protected $with = ['user_index'];
    //用户端-个人中心-意见反馈
    public function add()
    {
        $this->checkLogin();
        $post = param();
        if(!isset($post['content']) || !isset($post['id'])) return msgerror('参数缺失');
        $data = [
            'business_id'=>$post['id'],
            'content'=>$post['content'],
            'user_index_id'=>$this->userinfo['id']
        ];
        $this->model->save($data);
        return datasuccess([],'反馈成功');
    }
    //商户端-反馈消息-列表
    public function index()
    {
        $this->businessCheckLogin();
        $limit = input('limit') ?: 20;
        $data = $this->model->where([['business_id','=',$this->businessinfo['id']]])->with($this->with)->order('id desc')->paginate($limit);
        return datasuccess($data);
    }

    //商户端-删除数据
    public function delete()
    {
        $this->businessCheckLogin();
        if (!input('post.id')) {
            return msgerror('缺少参数id');
        }
        if (strstr((string)input('post.id'), ',')) {
            $id = explode(',', input('post.id'));
        } else {
            $id = input('post.id');
        }
        $this->model::destroy($id);
        return datasuccess([], '删除成功');
    }
}